#!/bin/bash
#Usage: ./fmtlog <configfiles>

mybindir=.
PATH=$PATH:$mybindir
export PATH

fmt_log(){  # fmt_log <col_to_output> <ltype> <configs>
col_to_output=$1  
ltype=$2
keyword=$3
shift
shift
shift

while [ $1 ] ; do
local_dir=`cat $1 |grep -v "#" | grep $ltype | awk '{print $3}'`
logfiles=`find $local_dir/ftptemp | grep gz`   
echo "fmting : $logfiles"
zcat $logfiles | grep $keyword | removespace | awk '{ print '$col_to_output'}' > $local_dir/fmtout_$keyword
shift
done
}

#***********Main Start*************#

#output : logdate clientip  cs_host
fmt_log '$1,$4,$16' "main"  "OBSERVED" $* 
fmt_log '$1,$4,$16' "main"  "policy_denied" $*
 
fmt_log '$1,$4,$15' "ssl" "OBSERVED" $* 
fmt_log '$1,$4,$15' "ssl"  "policy_denied" $*

fmt_log '$1,$3,$5'  "cifs" "445.ALLOWED" $*


